<template>
  <div class="zh-wode">
    <div class="zh-wode-top" @click="handleToChangeTx">
      <div class="tx-left" :style="{'background-image': 'url(' + photo + ')'}" @click.stop="handlePopUpTx"></div>
      <div class="center-information">
        <div class="name">{{ nickName }}</div>
        <div class="tel">15836611174</div>
      </div>
      <div class="right-jt">
        <i class="iconfont icon-left"></i>
      </div>
    </div>

    <div class="zh-card">
      <div class="zh-box" @click="$router.push({ name: 'diy' })">
        <div class="position">√</div>
        <div class="title">自定义组件</div>
        <!-- <object :data="svg" width="300" height="100" type="image/svg+xml" /> -->
      </div>
    </div>

    <van-popup v-model="show" position="bottom" round>
      <div class="zh-popup-cell" v-for="item in 3" :key="item" >
        拍照{{ item }}
        <input class="upload-input" @change="upload"  name="file" type="file" accept="image/*"/>
      </div>
      <div class="zh-eee" style="background:#f7f8fa;height:10px"></div>
      <div class="zh-popup-cell" @click="show = false">取消</div>
    </van-popup>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      photo: localStorage.getItem('txImage') || require('@/assets/image/photo.jpg'),
      svg: require('../../assets/image/diycomponent.svg'),
      show: false

    }
  },
  computed: {
    ...mapState({ nickName: 'nickName' })
  },
  methods: {
    handleToChangeTx () {
      this.$router.push({
        path: '/person'
      })
    },
    upload (e) {
      this.show = false
      const file = e.target.files[0]
      const re = new FileReader()
      re.readAsDataURL(file)
      re.onload = function (re) {
        this.addedPreviewFile = re.result
      }
      setTimeout(() => {
        this.photo = re.result
        localStorage.setItem('txImage', re.result)
      }, 100)
    },
    handlePopUpTx () {
      this.show = true
    }

  }
}
</script>

<style lang="less" scoped>
  .zh-wode {
    .zh-wode-top {
      background: #1578ff;
      padding: 20px;
      display: flex;
      align-items: center;
      position: relative;

      .tx-left {
        width: 50px;
        height: 50px;
        border-radius: 4px;
        border: 2px solid #55b0ff;
        background-position: center !important;
        background-size: cover !important;
      }
      .center-information {
        margin-left: 10px;
        flex: 1;
        color: #fff;
        height: 50px;
        display: flex;
        justify-content: space-around;
        flex-direction: column;
        .name {
          font-size: 14px;
        }
        .tel {
          color: #c9ced7;
          font-size: 12px;
        }
      }
      .right-jt {
        width: 20px;
        color: #fff;
        .iconfont {
          font-size: 20px;
        }
      }
    }
    .zh-card {
      padding: 0 10px;
      .zh-box {
        border-radius: 5px;
        margin-top: 15px;
        padding: 10px;
        height: 120px;
        box-sizing: border-box;
        background: #fff;
        box-shadow: 2px 2px 8px 0px rgba(150,178,191,0.4);
        position: relative;
        .position {
          position: absolute;
          top: 0;
          right: 0px;
          width: 24px;
          height: 24px;
          font-size: 14px;
          background: #1578ff;
          display: flex;
          align-items: center;
          justify-content: center;
          border-bottom-left-radius: 120%;
          color: #fff;
        }
      }
    }
  }
</style>

<style lang="less">
  .zh-popup-cell {
    font-size: 16px;
    text-align: center;
    height: 50px;
    line-height: 50px;
    box-sizing: border-box;
    border-bottom: 1px solid #eee;
    padding: 0 15px;
    .upload-input {
      width: 100%;
      position: absolute;
      opacity: 0;
      top: 0px;
      left: 0px;
    }
  }
</style>
